package com.hbue.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hbue.springboot.pojo.TbAccount;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 账户管理模块映射器，在数据库表的字段和Java实体类的属性之间做映射
 */
@Repository
@Transactional
public interface TbAccountMapper extends BaseMapper<TbAccount> {

    /**
     * 修改密码
     * @param userName
     * @param userPwd
     * @return 执行update语句受影响的行数，大于0修改密码成功，否则修改密码失败
     */
    @Update("update tb_account set user_pwd = #{userPwd} where user_name = #{userName}")
    int modifyUserPwd(@Param("userName") String userName, @Param("userPwd") String userPwd);

    @Select("select * from tb_account where user_name = #{name} and user_role = 2")
    public TbAccount selectAccountByName(String name);
}
